package com.repository;

import com.entity.RoleAndMenu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.List;

/**
 * @author Yadasu
 * @date 2020/12/22 16:48
 */
public interface MenuAndRoleRepository  extends JpaRepository<RoleAndMenu,Integer> {

    @Query(value = "select * from  sys_roles_menus  where role_id=:id ",nativeQuery = true)
    List<RoleAndMenu>findAllByRid(@Param("id")Integer id);


    @Modifying
    @Transactional
    @Query(value = "insert  into sys_roles_menus (menu_id, role_id)values (?1,?2)",nativeQuery = true)
    Integer add(Integer mid, Integer rid);

    @Modifying
    @Transactional
    @Query(value = "delete  from sys_roles_menus where role_id=?1",nativeQuery = true)
    Integer delMenuInRole(Integer rid);


}
